#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

int cmp(void* p1, void* p2)
{
	return (*(int*)p1 - *(int*)p2);
}
void Swap(char* e1, char* e2,size_t width)
{
	int i = 0;
	for (i = 0; i < width; i++)
	{
		char tmp = *(e1+i);
		*(e1+i) = *(e2+i);
		*(e2+i) = tmp;
	}
}
void bubble_sort(void* base, size_t sz, size_t width, int(*compar)(void* p1, void* p2))
{
	int i = 0;
	for (i = 0; i < sz - 1; i++)
	{
		int j = 0;
		for (j = 0; j < sz - 1 - i; j++)
		{
			if (compar((char*)base + j * width, (char*)base + (j + 1) * width)>0)
			{
				Swap((char*)base + j * width, (char*)base + (j + 1) * width,width);
			}
		}
	}
}
int main()
{
	int arr1[] = { 3,2,4,5,6,9,8,7,1,0 };
	size_t sz = sizeof(arr1) / sizeof(arr1[0]);
	int j = 0;
	for (j = 0; j < sz; j++)
	{
		printf("%d ", arr1[j]);
	}
	printf("\n");
	bubble_sort(arr1, sz, sizeof(arr1[0]), cmp);
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%d ",arr1[i]);
	}
	return 0;
}